#!/bin/bash
#根据table的名字，返回table所在的目录
#mysql_datadir=$(/opt/mysql/bin/mysql -e "show variables like '%datadir%'"|awk 'NR==2{print $2}')
mysql_datadir=$(/opt/mysql/bin/mysql -e "select * from DISK_CONFIG" UAS|awk 'NR>1{print $2}')


if [[ $is_table_exist == 0 ]]; then
        echo "the table you input is not exist"
        exit 1
fi
input_table="$1"
table_name=$(echo $1|awk -F"2" '{print $1}')   #这里取出的table_name结尾多一个下划线_
table_date=${input_table:${#table_name}:8}
#去掉table_name的下划线
table_name=${table_name:0:$((${#table_name}-1))}

#计算table_date是一年中的第几天
day_of_year=$(date +"%j" --date="$table_date")
dir=$(expr $day_of_year % 90)
mysql_datadir_arr=($mysql_datadir)
#set -x
for ((i=0;i<${#mysql_datadir_arr[*]};i++))
do
        datadir=$(echo ${mysql_datadir_arr[i]})
        has=$(ls $datadir/DATA/${table_name}/${dir}/ | grep $input_table)
        if [[ -n $has ]];then
                echo "${datadir}/DATA/${table_name}/${dir}/"
                break;
        fi
done
